package org.jaaksi.view.tabview.tabview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.jaaksi.view.tabview.R;
import org.jaaksi.view.tabview.TabView;
import org.jaaksi.view.tabview.TimeController;

/**
 * Created by Fcy on 2016/6/19.
 */
public abstract class BaseTimeTabActivity extends Activity implements TabView.OnTabChangeListener, ITimeTabData, TimeController.ICustomTimeAction {

    protected TimeController mTimeController;
    // 设置子类可以配置
//    protected int[] timeKeyArr = new int[]{TODAY, WEEK, MOUTH, CUSTOM};

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView();

        TextView tv_from_time = (TextView) findViewById(R.id.tv_from_time);
        TextView tv_end_time = (TextView) findViewById(R.id.tv_end_time);
        mTimeController = TimeController.getInstance(initTimeKeyArr());
        mTimeController.bindTimeTextView(tv_from_time, tv_end_time);
        mTimeController.setCustomTimeAction(this);

        TabView tabView = (TabView) findViewById(R.id.tabView);
        tabView.setOnTabChangeListener(this);
        tabView.initContentArr(getResources().getStringArray(R.array.tab_arr));

        mTimeController.resetTime(tabView.getSelectPos());
    }

    protected abstract void setContentView();

    protected int[] initTimeKeyArr() {
        return new int[]{TODAY, WEEK, MOUTH, CUSTOM};
    }

    @Override
    public void onTabChange(int position) {
        // 这些逻辑都放在basetab中处理，只暴露给子类，需要传递一个array，暴露给子类一个onRefresh方法，提供position和时间戳
        mTimeController.resetTime(position);
        getData(mTimeController.getFromTime(), mTimeController.getEndTime());
    }

    protected abstract void getData(long fromTime, long endTime);
}
